EntityManager<TContext, TEntity>
Provides a base class for entity-specific business logic managers with built-in CRUD operations, audit trail support, and lifecycle event hooks. Handles common entity operations and automatically manages audit fields for entities that implement auditing interfaces.Syntax
Inheritance
Constructors
EntityManager
Parameters
- dataContext
TContext: The database context instance for data operations. Should be injected by the DI container. - messagePublisher
IMessagePublisher: The message publisher instance for publishing events. Should be injected by the DI container.
Methods
DeleteAsync
Parameters
- entities List<TEntity>:
- save bool:
Returns
Task<bool>DeleteAsync
Parameters
- entities List<TEntity>:
- context
TContext: - save bool:
Returns
Task<bool>DeleteAsync
Parameters
- entity
TEntity: - save bool:
Returns
Task<bool>DeleteAsync
Parameters
- entity
TEntity: - context
TContext: - save bool:
Returns
Task<bool>DirectDelete
Parameters
- predicate Expression<Func<TEntity, bool>>: An
to execute against the
Returns
intDirectDeleteAsync
Parameters
- predicate Expression<Func<TEntity, bool>>: An
to execute against the
Returns
Task<int>DirectUpdate
Parameters
- predicate Expression<Func<TEntity, bool>>: An
to execute against the - updateExpression Expression<Func<TEntity, TEntity>>: An
defining the updates to be performed on the records returned by the predicate.
Returns
intDirectUpdateAsync
Parameters
- predicate Expression<Func<TEntity, bool>>: An
to execute against the - updateExpression Expression<Func<TEntity, TEntity>>: An
defining the updates to be performed on the records returned by the predicate.
Returns
Task<int>InsertAsync
Parameters
- entities List<TEntity>: The collection of entities to be inserted.
- save bool: Whether to immediately save changes to the database. Defaults to true.
Returns
Task<bool> True if the entities were successfully inserted; otherwise, false.InsertAsync
Parameters
- entities List<TEntity>: The collection of entities to be inserted.
- context
TContext: The database context to use for the operation. - save bool: Whether to immediately save changes to the database. Defaults to true.
Returns
Task<bool> True if the entities were successfully inserted; otherwise, false.InsertAsync
Parameters
- entity
TEntity: The entity to be inserted. - save bool: Whether to immediately save changes to the database. Defaults to true.
Returns
Task<bool> True if the entity was successfully inserted; otherwise, false.InsertAsync
Parameters
- entity
TEntity: The entity to be inserted. - context
TContext: The database context to use for the operation. - save bool: Whether to immediately save changes to the database. Defaults to true.
Returns
Task<bool> True if the entity was successfully inserted; otherwise, false.OnDeletedAsync
Parameters
- entities List<TEntity>: The collection of entities that were deleted.
Returns
TaskOnDeletedAsync
Parameters
- entity
TEntity: The entity that was deleted.
Returns
Task<bool> True if post-deletion processing was successful; otherwise, false.OnDeletingAsync
Parameters
- entities List<TEntity>: The collection of entities to be deleted.
Returns
TaskOnDeletingAsync
Parameters
- entity
TEntity: The entity to be deleted.
Returns
TaskOnInsertedAsync
Parameters
- entities List<TEntity>: The collection of entities that were inserted.
Returns
TaskOnInsertedAsync
Parameters
- entity
TEntity: The entity that was inserted.
Returns
Task<bool> True if post-insertion processing was successful; otherwise, false.OnInsertingAsync
Parameters
- entities List<TEntity>: The collection of entities to be inserted.
Returns
TaskOnInsertingAsync
Parameters
- entity
TEntity: The entity to be inserted.
Returns
TaskOnUpdatedAsync
Parameters
- entities List<TEntity>: The collection of entities that were updated.
Returns
TaskOnUpdatedAsync
Parameters
- entity
TEntity: The entity that was updated.
Returns
Task<bool> True if post-update processing was successful; otherwise, false.OnUpdatingAsync
Parameters
- entities List<TEntity>: The collection of entities to be updated.
Returns
TaskOnUpdatingAsync
Parameters
- entity
TEntity: The entity to be updated.
Returns
TaskResetAuditProperties<TDbObservable>
Parameters
- entity
TDbObservable: The entity whose audit properties should be reset.
UpdateAsync
Parameters
- entities List<TEntity>: The collection of entities to be updated.
- save bool: Whether to immediately save changes to the database. Defaults to true.
Returns
Task<bool> True if the entities were successfully updated; otherwise, false.UpdateAsync
Parameters
- entities List<TEntity>: The collection of entities to be updated.
- context
TContext: The database context to use for the operation. - save bool: Whether to immediately save changes to the database. Defaults to true.
Returns
Task<bool> True if the entities were successfully updated; otherwise, false.UpdateAsync
Parameters
- entity
TEntity: The entity to be updated. - save bool: Whether to immediately save changes to the database. Defaults to true.
Returns
Task<bool> True if the entity was successfully updated; otherwise, false.UpdateAsync
Parameters
- entity
TEntity: The entity to be updated. - context
TContext: The database context to use for the operation. - save bool: Whether to immediately save changes to the database. Defaults to true.
Returns
Task<bool> True if the entity was successfully updated; otherwise, false.Remarks
This manager provides comprehensive entity lifecycle management including:- Automatic audit trail creation for entities implementing
, - User tracking for entities implementing
, - Virtual hooks for custom business logic before and after CRUD operations
- Batch operations support for improved performance
- Thread-safe interface caching for performance optimization